<div class="layuimini-container">
    <div class="layuimini-main">
        <!-- 年级添加头部 -->
        <div class="head">
            <h2><strong>年级相册信息管理</strong></h2>
        </div>
        <!-- 分割线 -->
        <div>
            <hr class="layui-border-black">
        </div>
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">年级</label>
                <div class="layui-input-block">
                    <input type="text" name="gradename" lay-verify="required" lay-reqtext="年级名不能为空" placeholder="请输入年级名" value="" class="layui-input">
                    <tip>填写年级的名称，如 2019。</tip>
                </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form', 'table', ], function() {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function(data) {
            console.log(data)
            var postData = {
                "grade": data.field.gradename,
            }
            console.log(postData)
            jq1111.ajax({
                type: "POST",
                crossDomain: true,
                url: BasePath+"api/School/AddGrade",
                contentType: "application/json",
                dataType: "json",
                xhrFields: {
                    withCredentials: true
                },
                data: JSON.stringify(postData),
                success: function(message) {
                    console.log(message);
                    var index = layer.alert(message.msg, {
                        title: message.msg
                    }, function() {
                        // 关闭弹出层
                        layer.close(index);
                        layer.close(parentIndex);
                        table.reload("currentTableId",{})
                    });
                },
                error: function(message) {
                    var index = layer.alert(message.responseJSON.msg, {
                        title: message.responseJSON.msg
                    }, function() {
                        // 关闭弹出层
                        layer.close(index);
                    });
                },
            });
            return false;
        });
    });
</script>